package com.neusoft.his.sys.service.impl;

import com.neusoft.his.sys.entity.CommonResult;
import com.neusoft.his.sys.entity.Dept;
import com.neusoft.his.sys.mapper.DeptMapper;
import com.neusoft.his.sys.service.IDeptService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.awt.dnd.DnDConstants;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 东软教育集团
 * @since 2022-08-24
 */
@Service
public class DeptServiceImpl extends ServiceImpl<DeptMapper, Dept> implements IDeptService {
	@Autowired
	DeptMapper deptMapper;
	
	@Override
	public CommonResult getAll() {
		List<Dept> lds = deptMapper.selectList(null);
		CommonResult result = new CommonResult<List<Dept>>(lds);
		return  result;
	}

	@Override
	public List<Dept> getByDname(String danme) {
		// TODO Auto-generated method stub
		return deptMapper.getByDname(danme);
	}

	@Override
	public CommonResult delById(int deptno) {
		int i =  deptMapper.deleteById(deptno);
		CommonResult result= null;
		if (i==1) {
			result = new CommonResult<Integer>(1);
		}else {
			result = new CommonResult<>();
			result.setStatus(250);
		}
		return result;
	}

	@Override
	public CommonResult addDept(Dept dept) {
		int i =  deptMapper.insert(dept);
		CommonResult result= null;
		if (i==1) {
			result = new CommonResult<Integer>(dept.getDeptno());
			result.setStatus(202);
		}else {
			result = new CommonResult<>();
			result.setStatus(250);
		}
		return result;
	}

	@Override
	public CommonResult modDept(Dept dept) {
		int i =  deptMapper.updateById(dept);
		CommonResult result= null;
		if (i==1) {
			result = new CommonResult<Integer>(dept.getDeptno());
			result.setStatus(203);
		}else {
			result = new CommonResult<>();
			result.setStatus(250);
		}
		return result;
	}

	 
	
}
